package fan.com.httpframe.http;


import fan.com.httpframe.app.ToastManager;
import fan.com.httpframe.http.bean.BaseBean;
import fan.com.httpframe.http.exception.ExceptionHandle;
import fan.com.httpframe.utils.LogUtil;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by fanliang on 18/1/3.
 */

public abstract class BaseSubscriber<T extends BaseBean> implements Observer<T> {

    private Disposable disposable;

    @Override
    public void onSubscribe(Disposable d) {
        disposable = d;
    }


    @Override
    public void onComplete() {

    }

    @Override
    public void onError(Throwable e) {
        ExceptionHandle.ResponeThrowable throwable = ExceptionHandle.handleException(e);
        ToastManager.manager.show(throwable.message);
        e.printStackTrace();
        LogUtil.e("liangfan......e = ");
//        completed();

    }

    @Override
    public void onNext(T t) {

        //        completed();
        if("200".equals(t.getCode())){
            result(t);
        }else{
            ToastManager.manager.show(t.getMessage());
        }

    }

    public abstract void result(T t);
//    public abstract void completed();

}
